package com.example.fresh_fruit.controller;

import com.example.fresh_fruit.dto.DeliveryDto;
import com.example.fresh_fruit.service.DeliveryDtoService;
import com.example.fresh_fruit.util.Result;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * @author :飞天の鱼
 * @date : 2022/8/26 10:08
 */
@Slf4j
@RestController
@RequestMapping("/DeliveryDto")
public class DeliveryDtoController {

    @Autowired
    private DeliveryDtoService deliveryDtoService;


    @PostMapping("/insert")
    public Result insertDelivery(@RequestBody DeliveryDto deliveryDto) {
        int insertDelivery = deliveryDtoService.insertDelivery(deliveryDto);
        if (insertDelivery == 1) {
            return Result.fail("无此订单号，订单号错误！");
        } else if (insertDelivery == 3) {
            return Result.fail(":商品id出错或者不存在");
        } else if (insertDelivery == 4) {
            return Result.fail("实际数量加入出错");
        }
        return Result.ok("发货完成");
    }

}
